<?php
/**
 * Created by PhpStorm.
 * User: Liulibao
 * Date: 2020/1/4
 * Time: 12:09
 */

namespace app\home\controller;


use app\common\model\Member;
use app\common\model\Fupersonal;
use think\Lang;

class Servicepersonal extends BaseSeller
{
    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'home/lang/' . config('default_lang') . '/sellermember.lang.php');
    }

    /**
     * Notes: 运营商下服务人员列表
     * User: shen
     * Date: 2020/4/27
     * Time: 8:52
     * @return mixed
     */
    public function index()
    {

        $Fupersonal_model = new Fupersonal();
        $mobile = trim(input('mobile', ''));
        if ($mobile) {
            $condition['ds_fuwu_personal.phone'] = $mobile;
        }
        $search_skillid = trim(input('search_skillid', ''));
        if (isset($search_skillid) && $search_skillid != '') {
            $condition['ds_fuwu_personal.skillid'] = $search_skillid;
        }
        $search_grade = trim(input('search_grade', ''));
        if (isset($search_grade) && $search_grade != '') {
            $condition['ds_fuwu_personal.gradeid'] = $search_grade;
        }

        $condition['ds_fuwu_personal.prev'] = $_SESSION['home']['member_id'];
        $condition['ds_fuwu_personal.prevtype'] = 2;

        $member_list = $Fupersonal_model->getList($condition, 'ds_fuwu_personal.*,s.name as skillname,g.name as gradename', 10);
        $skillArr = model('fuskill')->getList(['status' => 1], 'id,name');
        $gradeArr = model('fugrade')->getList(['status' => 1], 'id,name', 0, 'id asc');
        $this->assign('skillArr', $skillArr);
        $this->assign('gradeArr', $gradeArr);
        $this->assign('search_grade', trim(input('search_grade', '')));
        $this->assign('search_skillid', trim(input('search_skillid', '')));
        $this->assign('mobile', $mobile);
        $this->assign('member_list', $member_list);

        $this->assign('show_page', $Fupersonal_model->page_info->render());
        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('Servicepersonal');
        /* 设置卖家当前栏目 */
        $this->setSellerCurItem('index');
        return $this->fetch($this->template_dir . 'index');
    }

    /**
     * Notes: 获取服务人员详细信息
     * User: shen
     * Date: 2020/4/27
     * Time: 8:52
     * @return mixed
     */
    public function service_info()
    {
        $id = input('id/d', '');
        if (!$id) {
            $this->error('操作失败');
        }
        $model = model('fupersonal');
        $data = $model->info(['id' => input('id')]);
        $skillArr = model('fuskill')->info(['status' => 1, 'id' => $data['skillid']], 'id,name');
        $gradeArr = model('fugrade')->info(['status' => 1, 'id' => $data['gradeid']], 'id,name');
        $weekArr = getWeek();
        $this->assign('weekArr', $weekArr);
        $this->assign('skillArr', $skillArr);
        $this->assign('gradeArr', $gradeArr);
        $this->assign('data', $data);
        /* 设置卖家当前菜单 */
        $this->setSellerCurMenu('Servicepersonal');
        /*  /* 设置卖家当前栏目 */
        $this->setSellerCurItem('index');
        return $this->fetch($this->template_dir . 'service_info');
    }

    /**
     * Notes:移除服务人员
     * User: shen
     * Date: 2020/4/27
     * Time: 11:46
     */
    public function remove()
    {
        $id = input('id/d', '');
        if (!$id) {
            $this->error('操作失败');
        }

        $update_data = [
            'prevtype' => 1,
            'prev' => 0,
            'prevcode' => '',
        ];

        $res = db('fuwu_personal')->where('id', $id)->data($update_data)->update();
        if ($res) {
            ds_json_encode(10000, '操作成功');
        } else {
            ds_json_encode(10001, '操作失败');
        }
        

    }

    /**
     * Notes: 详情中查看图片
     * User: shen
     * Date: 2020/4/27
     * Time: 14:29
     * @return string
     */
    public function imgs()
    {
        $data  = input('img');
        if ($data) {
            if ((strpos($data, 'https://') === false) && (strpos($data, 'http://') === false)) {
                return '图片格式不正确';
            }
            $statsu = input('status') ? input('status') : 0;
            if ($statsu) {
                return '<div  align="center"><img src="' . $data . '" height="350px;" /></div>';
            }
            return '<div  align="center"><img src="' . $data . '" height="440px;" /></div>';
        } else {
            return '未上传';
        }
    }


    /**
     *    栏目菜单
     */
    function getSellerItemList()
    {
        $menu_array[] = array(
            'name' => 'index',
            'text' => "服务人员",
            'url' => url('Servicepersonal/index'),
        );

        return $menu_array;
    }

}
